
 /**
 * BaseOperatorBeforeAdvice.java.java.
 * User: BrianChen Date: 2012-6-5 上午11:02:21
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.core.aop.interceptor;

import java.lang.reflect.Method;
import java.util.Date;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.aop.MethodBeforeAdvice;

import com.collapsar.core.service.BaseUserAwareManager;

/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-6-5 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-6-5 上午11:02:21
 * @version 1.0
 * @see
 * 将一些通用操作进行封装，通过Spring的IOC来解决一些繁琐的重复性工作，对程序解耦
 * 例如：当对某一业务对象进行操作时候，记录操作人 和 操作时间
 */
public class BasicOperatorMethodBeforeAdvice implements MethodBeforeAdvice{

	@Override
	public void before(Method method, Object[] objects, Object o)
			throws Throwable {
		if(o instanceof BaseUserAwareManager){
			BaseUserAwareManager manager = (BaseUserAwareManager)o;
			String userAccount = manager.getCurrentUser().getAccount();
			Object entity = objects[0];
			if(userAccount != null && entity != null){
				try{
					PropertyUtils.setProperty(entity, "lastOperator", userAccount);
					PropertyUtils.setProperty(entity, "lastModifyDate", new Date());
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
		}
	}

}

